package com.prs.crm.service.person.impl;

import java.io.File;
import java.util.Collection;
import java.util.List;

import com.prs.crm.context.Attach;
import com.prs.crm.context.Constrains;
import com.prs.crm.context.FileUtil;
import com.prs.crm.dao.person.DossierDao;
import com.prs.crm.domain.person.Department;
import com.prs.crm.domain.person.Dossier;
import com.prs.crm.service.impl.BaseServiceImpl;
import com.prs.crm.service.person.DossierService;

public class DossierServiceImpl extends BaseServiceImpl<Dossier, DossierDao> implements DossierService{

	@Override
	public void saveDossier(Dossier dossier, File picImg, String picImgFileName,
			File resumeAttach, String resumeAttachFileName) {
		Attach pAttach=FileUtil.getInstance().saveFile(picImg, picImgFileName, "", Constrains.UPLOAD_DIR_RESUME);
		Attach rAttach=FileUtil.getInstance().saveFile(resumeAttach, resumeAttachFileName, "", Constrains.UPLOAD_DIR_RESUME);
		if (pAttach.getSrc()!=null) {
			dossier.setPicImg(pAttach.getSrc());
		}
		if (rAttach.getSrc()!=null) {
			dossier.setResumeFile(rAttach.getSrc());
		}
		this.getDao().save(dossier);
	}

	@Override
	public Collection<Dossier> findByDepartment(Department department) {
		return this.getDao().findByDepartment(department);
	}

	@Override
	public List<Dossier> getAllDossier() {
		return this.getDao().getAllDossier();
	}

	@Override
	public Dossier getDossierById(Integer id) {
		return this.getDao().getDossierById(id);
	}
}
